function(rwkv_add_test source)
    get_filename_component(TEST_TARGET ${source} NAME_WE)
    add_executable(${TEST_TARGET} ${source})
    if (GGML_CUDA_SOURCES)
        set_property(TARGET ${TEST_TARGET} PROPERTY CUDA_ARCHITECTURES OFF)
    endif()
    target_link_libraries(${TEST_TARGET} PRIVATE ggml rwkv)
    target_include_directories(${TEST_TARGET} PRIVATE ${CMAKE_SOURCE_DIR}/ggml/include ${CMAKE_SOURCE_DIR}/ggml/src)
    add_test(NAME ${TEST_TARGET} COMMAND $<TARGET_FILE:${TEST_TARGET}> ${ARGN})
    if (RWKV_STATIC)
        if(RWKV_HIPBLAS)
         message(FATAL_ERROR "Static linking not supported for HIP/ROCm")
        else()
            get_target_property(target_LINK_OPTIONS ${TEST_TARGET} LINK_OPTIONS)
            list(REMOVE_ITEM target_LINK_OPTIONS "-static")
            set_target_properties(${TEST_TARGET} PROPERTIES LINK_OPTIONS "${target_LINK_OPTIONS}")
        endif()
    endif()
endfunction()

file(COPY tiny-rwkv-4v0-660K-FP32.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-4v0-660K-FP16.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-4v0-660K-Q5_0.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-4v0-660K-Q5_1.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY expected-logits-4v0-660K.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY tiny-rwkv-5v1-730K-FP32.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v1-730K-FP16.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v1-730K-Q5_0.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v1-730K-Q5_1.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY expected-logits-5v1-730K.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY tiny-rwkv-5v2-730K-FP32.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v2-730K-FP16.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v2-730K-Q5_0.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-5v2-730K-Q5_1.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY expected-logits-5v2-730K.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY tiny-rwkv-6v0-3m-FP32.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-6v0-3m-FP16.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-6v0-3m-Q5_0.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-6v0-3m-Q5_1.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY expected-logits-6v0-3m.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

file(COPY tiny-rwkv-7v0-834K-FP32.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-7v0-834K-FP16.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-7v0-834K-Q5_0.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY tiny-rwkv-7v0-834K-Q5_1.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})
file(COPY expected-logits-7v0-834K.bin DESTINATION ${CMAKE_CURRENT_BINARY_DIR})

rwkv_add_test(test_ggml_basics.c)
rwkv_add_test(test_quantized_matmul_on_gpu.c)
rwkv_add_test(test_tiny_rwkv.c)
rwkv_add_test(test_quantization_format_compatibility.c)
rwkv_add_test(test_logit_calculation_skipping.c)
rwkv_add_test(test_eval_sequence_in_chunks.c)
rwkv_add_test(test_context_cloning.c)
